
#include "messages_channels.hpp"
#include "subscription.hpp"


namespace fasys{

subscription::~subscription()
{
  delete _messages;
};


subscription::subscription(channels_container* cc)
  :  observer(0)
  , _messages(0)
  , _channels(cc)
{
}

subscription::subscription(const subscription&  cc)
{
  *this = cc;
  cc._messages = 0;
}

// создать, обновить канал подписки
channel_id_t subscription::create(const std::string& channel, size_t min_size, size_t max_size )
{
  if ( _messages == 0 )
    _messages = new messages_channels(_channels);

  channel_id_t channel_id = _messages->create(channel, min_size, max_size);
  return channel_id;
}

// удалить канал подписки
channel_id_t subscription::remove(const std::string& channel)
{
  // TODO: удалить канал
  return 0;
}

void subscription::republish(const message& m)
{
  if ( _messages == 0 )
    _messages = new messages_channels(_channels);
  _messages->republish(m);
}

void subscription::move_messages(std::list<message>& ml)
{
  if ( _messages == 0 )
    return;
  _messages->move_all(ml);
}

}

